import requests
import parsel

url = 'http://www.netbian.com/meinv/'

resp = requests.get(url=url)
# print(resp.text)
selector = parsel.Selector(resp.text)

lis_list = selector.css('#main div.list ul li a::attr("href")').getall()[:-1]
# titles = selector.css('#main div.list ul li a::attr("title")').getall()[:-1]

for info in lis_list:
    # print(info)
    # 拼接详情页连接
    done = 'http://www.netbian.com/'
    url_2 = done + info
    resp_2 = requests.get(url=url_2)
    selector = parsel.Selector(resp_2.text)
    # 高清图片链接
    img_url = selector.css('#main div.endpage div p a img::attr("src")').get()
    # 保存图片 访问二进制数据
    # print(img_url)
    try:
        name = img_url.split('/')[-1]   # 拿出链接最后作为图片名字
        # print(name)
        resp_3 = requests.get(url=img_url)
        with open(f'img/{name}', mode='wb') as f:
            f.write(resp_3.content)

        print(f'{name}, 保存成功！！！')
    except:
        pass
















